import {
  deitPhotoFiles,
  deitProfile,
  getUserInfo,
  getUserProfile,
} from '@/api/user';
import { AppDispatch } from '..';
import { Profile } from '../reducer/user';

export const actionProfile = () => {
  return async (dispacth: AppDispatch) => {
    const res = await getUserInfo();
    dispacth({
      type: 'user/getProfile',
      payload: res.data,
    });
  };
};
export const actionUserProfile = () => {
  return async (dispacth: AppDispatch) => {
    const res = await getUserProfile();
    dispacth({
      type: 'user/getUserProfile',
      payload: res.data,
    });
  };
};
export const actionfiles = (file: FormData) => {
  return async (dispacth: AppDispatch) => {
    const res = await deitPhotoFiles(file);
    // console.log(`res`, res);
    dispacth({
      type: 'user/editFile',
      payload: res.data,
    });
  };
};
export const actionEditProfile = (data: Partial<Profile>) => {
  return async (dispacth: AppDispatch) => {
    await deitProfile(data);
    // console.log(`res`, res);
    dispacth({
      type: 'user/editFile',
      payload: data,
    });
  };
};
